var zg_GameFilter = {
	_loadPage : function (page) 
	{
		var os 		= $('#osId').val();
		var parent 	= $('#parentId').val();
		var cat 	= $('#catId').val();
		var type 	= $('#type').val();
		this._filter( os, parent, cat, type, page, null, null);
	},
	_loadPageTag: function (page) 
	{
		var os 	= $('#osId').val();
		var tagName	= $('#tagName').val();
		var urlPost   = "/mg/tags/getlistproduct";
		this._filter( os, 0, 0, 0, page, tagName, urlPost);
	},
	_loadType : function (type) 
	{	
		var os 		= $('#osId').val();
		var parent 	= $('#parentId').val();
		var cat 	= $('#catId').val();
		var page 	= 1;
		$('#type').val(type);
		this._filter( os, parent, cat, type, page, null, null);
	},
	_loadCat : function (parentId,catId)
	{
		var os 		= $('#osId').val();
		var type 	= $('#type').val();
		var page 	= 1;
		$('#parentId').val(parentId);
		$('#catId').val(catId);
		this._filter( os, parentId, catId, type, page, null, null);
	},
	_filter : function(os, parent, cat, type, page, tag, postUrl) 
	{
		
		$('#NoResult').hide();
		
		if(postUrl != null){
		  var urlPost = postUrl;
		}else{
		  var urlPost = "/mg/cat/getlistproduct";
		}
		//$('#ListProduct').html('<p style="align:center;width: 10%;height: auto;margin-left:auto;margin-right:auto;"><img width="32px" height="32px" src="' + imgUrl + '/images/loading2.gif"></p>');
		//$('#ListProduct').show();
		
		var currentHref = $('#typeUrl').val();
		//$('#PageNavId').hide();
		$.ajax( {
					type : "POST",
					dataType : 'json',
					url : urlPost,
					// you can use an object here
					data : {
						os 		: os,
						parent 	: parent,
						cat 	: cat,
						type	: type,
						page 	: page,
						tag	: tag,
						currentHref : currentHref
					},
					success : function(res) {
						var html = '';
						
					if (res.status == 1) {
						var listProduct = res.result;
						$.each(listProduct,function() {
						    var title = prefix + ' ' + this.pName;
						    html += '<li><div class="app-box"><div class="app-thumb"><img src="'+urlProduct80+this.pImage+'"alt="'+title+'" class="lazy" /><a href="'+this.link_seo+'" class="mask white-mask" title="'+title+'"></a></div><!--end .app-thumb--><p class="app-title-2 center"><a href="'+this.link_seo+'" title="'+title+'">'+this.pName+'</a></p><p class="app-fact-2  center">'+this.cName+'</p><p class="ellipsis  center">Lượt tải: '+this.counter+'</p>' + this.ratingHelper + '<a href="javascript:void(0);" id="'+this.pvId+'" class="download-btn Download">Tải</a></div><!--end .app-box--></li>';
						});
						$('#NoResult').hide();
						if (res.pagination != '') {
							$('#PageNavId').html(res.pagination);
							$('#PageNavId').show();
						}
						$('#ListProduct').html(html);
						$('#ListProduct').show();
						
						//raty2();
					} else {
						$('#PageNavId').html("");
						$('#PageNavId').show();
						$('#ListProduct').hide();
						$('#NoResult').show();
					}
					$(".site-path").html(res.breadcum);
					//alert(res.breadcum);
					$(".site-path").show();
				},
				error : function() {
				}
				});
	}
};

$('#GamesTabCate li').each(function(i){
		$(this).click(function(){
			if($(this).attr('data-disable') == '1'){
				return false;
			}
			$("#GamesTabCate li").removeClass("current");
			var newLink = $(this).find('a').attr('href');
			$('#typeUrl').val(newLink);
			var typeTemp = $(this).find('a').attr('rel');
			$(this).attr('class','current');
			$('#type').val(typeTemp);
			zg_GameFilter._loadType(typeTemp);

			return false;
		});
	});
	

function loadCat(parentId,catId,nameSeo){
	$(".danhsach-list li").removeClass("current");
	var catBlockId = "#" + nameSeo;
	$(catBlockId).attr('class','current');
	zg_GameFilter._loadCat(parentId,catId);
}

function loadPage(page){
	if ((controller == "detail" && action == "cat")
		|| (controller == "book" && action == "content")
	) {
		zg_GameFilter._loadPage(page);
	}else if ((controller == "tags" && action == "index")){
		zg_GameFilter._loadPageTag(page);
	}else{
		loadPageComment(page);
	}
}

$(document).ready(function() {
   //raty2();
     jQuery(".sbox").each(function(){
				var self = jQuery(this);
				self.find("> .sbox-loop > .game-slist-wrapper").hide();
				var actTab = self.find(" > ul.sbox-tabs > li.current").prevAll().length;
				self.find("> .sbox-loop > .game-slist-wrapper").eq(actTab).show();
				jQuery(this).find(" > .sbox-loop > ul.sbox-tabs > li > a").bind("click",function(){
					var activeContent = jQuery(jQuery(this).attr("rel"));
					self.find("> .sbox-loop > ul.sbox-tabs > li.current").removeClass("current");
					jQuery(this).parent().addClass("current");
					var href = jQuery(this).attr("hrefTemp");
					self.find("> .sbox-bottom > a").attr("href",href);
					self.find(" > .sbox-loop > .game-slist-wrapper").hide();
					activeContent.show();
					return false;
				});
			});
});
